#!/bin/bash

vim_install_path=~/.lvim

config_file() {
    line_separator "Copy Config Files ..." c
    cp ${ROOT_PATH}/bashrc ~/.bashrc && line_separator '~/.bashrc'
    cp ${ROOT_PATH}/inputrc ~/.inputrc && line_separator '~/.inputrc'
    cp ${ROOT_PATH}/gitconfig ~/.gitconfig && line_separator '~/.gitconfig'
    if [ `tmux -V | cut -d ' ' -f 2 -s | awk '{print int($0)}'` -ge 2 ]; then
        cp ${ROOT_PATH}/tmux2.conf ~/.tmux.conf && line_separator '~/.tmux.conf'
    else
        cp ${ROOT_PATH}/tmux1.conf ~/.tmux.conf && line_separator '~/.tmux.conf'
    fi
}

config_vim() {
    line_separator "Set Up Lvim ..." v
    test -e $vim_install_path && rm $vim_install_path -rf
    git clone https://gitee.com/littlelot/lvim.git $vim_install_path
    cd $vim_install_path
    ./linux_install.sh
    cd ${ROOT_PATH}
}

config_ssh() {
    line_separator "Set Up SSH Authorized Keys ..." s
	test -e ~/.ssh || mkdir ~/.ssh
    chmod 700 ~/.ssh
    test -e ~/.ssh/authorized_keys || touch ~/.ssh/authorized_keys
    chmod 644 ~/.ssh/authorized_keys
    for pub_key in ${ROOT_PATH}/pubkey/*
    do
        cat $pub_key >> ~/.ssh/authorized_keys
    done
}

reboot_server() {
    line_separator "" r
    local i=3
    for index in `seq 1 3`
    do
        if [ x"$index" != x1 ]; then
            echo -ne "\033[u\033[1K"
        fi
        echo -ne "\033[sInitial Configuration(Installation) Complete,Server Will Reboot After $i Seconds ..."
        let 'i -= 1'
        sleep 1
    done
    line_separator ""
    reboot
}

source lib/func.sh
